package com.operation;

import java.util.HashMap;
import java.util.Map;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

import org.json.JSONObject;


import com.util.Log4gUtil;
import com.util.Md5Util;
import com.util.RandomUtil;

public class SendMC {
	private static ResourceBundle bundle = PropertyResourceBundle.getBundle("com.config.sendMC");
	
	private static String singleUrl= bundle.getString("sendSingleUrl");
	private static String stext = bundle.getString("stext");
	private static String sdkappid =bundle.getString("sdkappid");
	private static String appkey =bundle.getString("appkey");
	
	private static String voiceUrl = bundle.getString("sendVoiceUrl");

	//private  static final String singleUrl="https://yun.tim.qq.com/v3/tlssmssvr/sendsms?sdkappid=1211&random=";
	/**
	 * 单发短信验证码
	 * @param phone
	 * @param code
	 * @return
	 * @throws Exception
	 */
	public static String  getSendSingle(String phone , String code) throws Exception{
		
		//String msg="登录Wi-Fi网络验证码是："+code;//短信内容
		String msg = stext+code;
		String sig = Md5Util.getMd5(appkey+phone);//凭证
		String random = RandomUtil.getRandom(6);//随机数
		String url = singleUrl+"?sdkappid="+sdkappid+"&random="+random;//url
	
		JSONObject j = new JSONObject();
		JSONObject json = new JSONObject();
		j.put("nationcode", "86");
		j.put("phone", phone);
		json.put("tel", j);
		json.put("type", "0");
		json.put("msg", msg);
		json.put("sig", sig);
		json.put("extend","");
		json.put("ext", "");
		HttpSendUrl send = new HttpSendUrl();
		//发送
		String sendRequest = send.getSendRequest(url, json.toString(),"POST",4000);
		//接收
		JSONObject js = new JSONObject(sendRequest);
		String  result = js.get("result").toString();
		Log4gUtil.Info("getSendSingle","", "单发短信验证码结果", sendRequest, "", "");
		return result;
	} 
	
	/**
	 * 
	 * 语音信息验证码
	 * @param phone
	 * @param code
	 * @return
	 * @throws Exception
	 */
	public static String getSendVoice(String phone,String code) throws Exception{
		String msg=code;//短信内容
		String sig = Md5Util.getMd5(appkey+phone);//凭证
		String random = RandomUtil.getRandom(6);//随机数
		String url = voiceUrl+"?sdkappid="+sdkappid+"&random="+random;//url
		JSONObject j = new JSONObject();
		JSONObject json = new JSONObject();
		j.put("nationcode", "86");
		j.put("phone", phone);
		json.put("tel", j);
		json.put("msg", msg);
		json.put("sig", sig);
		json.put("ext", "");
		HttpSendUrl send = new HttpSendUrl();
		//发送
		String sendRequest = send.getSendRequest(url, json.toString(),"POST",4000);
		JSONObject js = new JSONObject(sendRequest);
		String  result = js.get("result").toString();
		Log4gUtil.Info("getSendVoice","", "语音信息验证码结果", sendRequest, "", "");
		return result;
	}
	
	public static void main(String[] args) throws Exception {
		//SendMC.getSendSingle("13128901391", "121121");
		SendMC.getSendVoice("13128901391", "1234");
	}
}
